var inicio = 0;

$(document).ready(function () {
    
    $(window).resize(iniciar);
    $(window).scroll(iniciar);
    iniciar();
});     

function iniciar(){ 
    
    var tempo = 2000;
    
    if(inicio == 1){
        telaTime();
    }else{
        setTimeout( function(){
            telaTime();
            loader();
            inicio = 1;
        }  , tempo);
        
    }
    
}

function telaTime(){
    
    var w_li = '';
    var h_li = '';
    var w_tela = $(window).width();
    var h_tela = $(window).height();
    var n_ele = $('.tl_menu li').size();
    var div = n_ele > 3 ? 2 : 1;

    switch (n_ele) {
        case 1:
            w_li = '100%';
            break;

        case 2:
            w_li = '50%';
            break;

        case 3:
            w_li = '33.33%';
            break;

        case 4:
            w_li = '50%';
            break;

        case 5:
            w_li = '33.33%';
            break;

        case 6:
            w_li = '33.33%';
            break;

        default: w_li = '33.33%';
    }

    h_li = parseInt(h_tela) / div;

    $('.tl_menu li').css('width', w_li);
    $('.tl_menu li').css('height', h_li);

    var w_cntimg = $('.content_img').width();
    var h_cntimg = $('.content_img').height();
    w_cntimg = parseInt(w_cntimg) / 2;
    h_cntimg = parseInt(h_cntimg) / 2;
    w_cntimg = '-'+  w_cntimg.toString()+'px';
    h_cntimg = '-'+h_cntimg.toString()+'px';

    $('.content_img').css('margin-top', h_cntimg);
    $('.content_img').css('margin-left',w_cntimg);    
}

function loader(){ 
    $('.tl_loader').fadeOut(); 
}